package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.shop.dao.EvaluateTagDAO;
import com.junzhiit.nengji.shop.model.EvaluateTag;

@Repository
public class EvaluateTagDAOImpl extends AbstractBaseDAO<EvaluateTag> implements EvaluateTagDAO {

	@Override
	public List<EvaluateTag> findAllByGoodsId(String goodsId) {
		StringBuffer sql=new StringBuffer();
		sql.append("select distinct et.id,et.name");
		sql.append(" from evaluate_tag et");
		sql.append(" inner join goods_evaluate_tag gt on et.id=gt.evaluate_tag_id");
		sql.append(" inner join user_evaluate ue on ue.id=gt.user_evaluate_id");
		sql.append(" where et.is_delete=?");
		
		StatementParameter param=new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		if(StringUtils.isNotBlank(goodsId)){
			sql.append(" and ue.goods_id=?");
			param.setString(goodsId);
		}
		
		return super.queryForList(sql.toString(), EvaluateTag.class, param);
	}

}
